<template>
  <div class="addAdderss">
    <!-- 头部 -->
    <van-nav-bar
      style="background-color:#f2f2f2"
      title="添加地址"
      left-text=""
      right-text=""
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="addAdderssBox">
      <van-address-edit
        :area-list="areaList"
        show-set-default
        show-search-result
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        :is-saving="loading"
      />
    </div>
  </div>
</template>

<script>
import SERVE from "@/axios/index";
import areaList from "@/assets/js/area.js";
export default {
  name: "addAdderss",
  data() {
    return {
      areaList,
      loading: false,
    };
  },
  mounted() {},
  methods: {
    onClickLeft() {
      this.$router.push("/addressManage");
    },
    onSave(item) {
      this.loading = true;
      SERVE.addAdderss({
        params: {
          cs_uid: window.localStorage.u_id,
          cs_xingming: item.name,
          cs_shouji: item.tel,
          cs_diqu1: item.province,
          cs_diqu2: item.city,
          cs_diqu3: item.county,
          cs_dizhi: item.addressDetail,
          cs_moren: item.isDefault,
        },
      })
        .then((res) => {
          this.loading = false;
          this.$notify({ type: res.data.zt==="yes" ? "success" :"warning", message: res.data.xinxi });
          let that = this;
          if(res.data.zt==="yes"){
            setTimeout(()=>{
              that.$router.push("/addressManage");
            },1000)
          }
        })
        .catch((err) => {
          this.loading = false;
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.addAdderss {
  .addAdderssBox {
    height: calc(100vh - 46px);
    overflow-y: scroll;
  }
}
</style>
